

#include "rmdirDispose.h"

void rmdirDispose(int netfd,MYSQL * mysql,char * username,char * spath){
    
    char sql[1024] = {0};
    sprintf(sql,"select * from usrfile where username = '%s' and path = '%s';",username,spath);
    int qret = mysql_query(mysql,sql);
    

    MYSQL_RES * table = mysql_store_result(mysql);

    if(mysql_num_rows(table)  == 0){
        send(netfd,"3",1,MSG_NOSIGNAL);
        return ;
    }
    MYSQL_ROW row = mysql_fetch_row(table);
    
    if(strcmp(row[5],"f") == 0){
        send(netfd,"1",1,MSG_NOSIGNAL);
        return ;
    }

    bzero(sql,sizeof(sql));
    sprintf(sql,"select * from usrfile where parent_id = '%s';",row[0]);
    mysql_query(mysql,sql);

    table = mysql_store_result(mysql);
    
    if(mysql_num_rows(table) != 0){
        send(netfd,"2",1,MSG_NOSIGNAL);
        return ;
    }
    else{
        bzero(sql,sizeof(sql));
        sprintf(sql,"delete from usrfile where username = '%s' and path = '%s';",username,spath);
        mysql_query(mysql,sql);
    }
    send(netfd,"0",1,MSG_NOSIGNAL);
    return ;
}
